package j2seperf.io;

import java.io.*;


public class CopyFile {

   public static void copy(String from, String to) 
                                 throws IOException{
      InputStream in = null;
      OutputStream out = null;      
      try {
         in = new FileInputStream(from);
         out = new FileOutputStream(to);        
         while (true) {
            int data = in.read();
            if (data == -1) {
               break;
            }
            out.write(data);
         }
         in.close();
         out.close();
      } finally {
         if (in != null) {
            in.close();
         }
         if (out != null) {
            out.close();
         }
      }
   }

   public static void main(String[] args) {
      try {
         Stopwatch timer = new Stopwatch().start();
         for (int i = 0; i < 4; i++) {
            copy("o.dat", "output.dat");
         }
         timer.stop();
         System.out.println(timer.getElapsedTime()/4);
      } catch (IOException e) {
         e.printStackTrace();
      }
   }
}

